package diseaseandcureadministration.disease;

import java.util.ArrayList;

import diseaseandcureadministration.cure.Cure;
import diseaseandcureadministration.registry.Registrable;
import diseaseandcureadministration.symptom.Symptom;

/**
 * Disease class describes name, symptoms and cure of known
 * diseases. Disease class implements Registrable interface so
 * it can be used in Registry classes
 * 
 * @author Peter Tolstrup Aagesen, ptaa@itu.dk
 *
 */
public class Disease implements Registrable 
{
	
	//Instance variables
	private String _name;
	private ArrayList<Symptom> _symptoms;
	private Cure _cure;
	
	public Disease(String name, ArrayList<Symptom> symptoms, Cure cure)
	{
		//Set variables
		_name = name;
		_symptoms = symptoms;
		_cure = cure;
	}
	
	@Override
	public String getName()
	{
		return _name;
	}
	
	/**
	 * getSymptoms is a getter for symptoms instance variable
	 * @return
	 */
	public ArrayList<Symptom> getSymptoms() 
	{
		return _symptoms;
	}
	
	/**
	 * getCure is getter for cure instance variable
	 * @return
	 */
	public Cure getCure()
	{
		return _cure;
	}
	
	@Override
	public boolean equals(Object o)
	{
		boolean isEqual = false;
		
		if(o instanceof Disease && o != null)
		{
			Disease other = (Disease)o;
			
			if(other.getName().equals(_name) && other.getCure().equals(_cure) && other.getSymptoms().size() == _symptoms.size())
			{
				for(Symptom symptom: other.getSymptoms())
				{
					if(!_symptoms.contains(symptom))
					{
						break;
					}
					
					isEqual = true;
				}
			}			
		}
		
		return isEqual;
	}
	
	@Override
	public String toString()
	{
		String diseaseAsString = _name + ", s:" + symptomsAsString() + "c:" + _cure.getName();
		return diseaseAsString;
	}
	
	/**
	 * symptomsAsString is a helper method for toString
	 * @return a comma separated list of symptoms
	 */
	private String symptomsAsString()
	{
		String symptomsString = "";
		
		//Add all symptoms names
		for(Symptom symptom: _symptoms)
		{
			symptomsString += symptom.getName() + ", ";
		}
		
		return symptomsString;
	}

}
